/*
 * Copyright (C) 2010 Moduad Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.homer.push.android.client;
import java.util.Random;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.homer.android.R;




public class Notifier {

	private static final String LOGTAG = LogUtil.makeLogTag(Notifier.class);

	private Random random = null;
	private Context context;
	
	private NotificationManager notificationManager;

	public Notifier(Context context) {
		this.context = context;
		this.notificationManager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);
		
		random = new Random(System.currentTimeMillis());
	}
	
	public void xmpp_notify(String notificationId, String apiKey, String title,
			String message, String uri, String from, String packetId) {
				
			
			// Notification
			Notification notification = new Notification();
			//notification.icon = getNotificationIcon();			;
			notification.icon = R.drawable.ic_launcher;
			notification.defaults = Notification.DEFAULT_LIGHTS;
			notification.defaults |= Notification.DEFAULT_VIBRATE;
			notification.defaults |= Notification.DEFAULT_SOUND;
			
			notification.flags |= Notification.FLAG_AUTO_CANCEL;
			notification.when = System.currentTimeMillis();
			//notification.number = GlobalConstants.iMessageNum;						
			//notification.tickerText = "你收到一条通知消息";
			String sMsg = title;//"你收到通知消息";
			notification.tickerText = sMsg;
			
			//int rad = random.nextInt();
			int	rad = R.id.aperture_icon;
			Intent detailsIntent = new Intent(ServiceManager.getContext(),	SystemConfig.getSystemNotifyContext()/*SystemNotifyActivity.class*/);

			//detailsIntent.putExtra(Constants.NOTIFICATION_URI, uri);
			detailsIntent.putExtra(Constants.NOTIFICATION_ID, notificationId);
			detailsIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
			detailsIntent.putExtra(Constants.NOTIFICATION_TITLE, title);
			detailsIntent.putExtra(Constants.NOTIFICATION_MESSAGE, message);
			detailsIntent.putExtra(Constants.NOTIFICATION_URI, uri);
			detailsIntent.putExtra(Constants.NOTIFICATION_FROM, from);
			detailsIntent.putExtra(Constants.PACKET_ID, packetId);

			/*detailsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			detailsIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
			detailsIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
			detailsIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);*/
			// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

			PendingIntent contentIntent = PendingIntent.getActivity(context,
					random.nextInt(), detailsIntent,
					PendingIntent.FLAG_UPDATE_CURRENT);
						
			notification.setLatestEventInfo(context, "Homer 安防套件", message,
					contentIntent);
			notificationManager.notify(rad, notification);
			//-------------------
//			MainActivity main = GlobalConstants.gMainActivity;
//			main.myhandler.sendMessage(main.myhandler.obtainMessage(5));
	}
	
//	public void center_notify() {
//						
//			// Notification
//			Notification notification = new Notification();
//			notification.icon = R.drawable.ic_launcher;
//			notification.defaults = Notification.DEFAULT_LIGHTS;
//			notification.defaults |= Notification.DEFAULT_VIBRATE;
//			
//			notification.sound = Uri.parse("android.resource://com.wellview.wphone/raw/bell");
//			notification.flags |= Notification.FLAG_AUTO_CANCEL;
//			notification.flags |= Notification.FLAG_INSISTENT;
//			notification.when = System.currentTimeMillis();
//			notification.tickerText = "有消息通知";
//						
//												
//			int	rad = 33453/*GlobalConstants.MSG_NotifyID */;
//			Intent detailsIntent = new Intent(context,	IntercomActivity.class);
//				
//			detailsIntent.putExtra("knock", "true");
//			detailsIntent.putExtra("rad", rad);
//			
//
//			detailsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//			detailsIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
//			detailsIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
//			detailsIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//			
//			PendingIntent contentIntent = PendingIntent.getActivity(context,
//					random.nextInt(), detailsIntent,
//					PendingIntent.FLAG_UPDATE_CURRENT);
//
//			
//			notification.setLatestEventInfo(context, "逸家乐", "有客来访",
//					contentIntent);
//			notificationManager.notify(rad, notification);
//			
//		
//	}
//		
//	public void update_notify() {
//		
//		// Notification
//		Notification notification = new Notification();
//		notification.icon = R.drawable.ic_launcher;
//		notification.defaults = Notification.DEFAULT_LIGHTS;
//		notification.defaults |= Notification.DEFAULT_VIBRATE;
//		notification.defaults |= Notification.DEFAULT_SOUND;
//		notification.flags |= Notification.FLAG_AUTO_CANCEL;
//		
//		notification.when = System.currentTimeMillis();
//		notification.tickerText = "版本升级通知";
//					
//											
//		int	rad = GlobalConstants.UPDATE_NotifyID ;
//		Intent detailsIntent = new Intent(context,	UpdateActivity.class);
//			
//
//		/*detailsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//		detailsIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
//		detailsIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);*/
//		detailsIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//		PendingIntent contentIntent = PendingIntent.getActivity(context, 0, detailsIntent, 0);
//		
//		notification.setLatestEventInfo(context, "版本升级", "有了新版本，点击升级",
//				contentIntent);
//		notificationManager.notify(rad, notification);
//		
//	
//}
	
}
